home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / sys / sysSysCall.c < prev    next >
C/C++ Source or Header  |  1991-05-07  |  27KB  |  621 lines

  1. /*
  2.  * sysSyscall.c --
  3.  *
  4.  *    Routines and structs for system calls.  Contains information
  5.  *    about each system call such as the number of arguments and how
  6.  *    to invoke the call for migrated processes.  All local
  7.  *    processes invoke system calls by copying in the arguments from
  8.  *    the user's address space and passing them to the kernel
  9.  *    routine uninterpreted.  When migrated processes invoke system
  10.  *    calls, when possible the arguments are passed to a generic
  11.  *    stub that packages the arguments and sends them to the home
  12.  *    node of the process through RPC.  This file contains
  13.  *    information about the sizes and types of each argument for
  14.  *    those procedures.  The generic stub is called with information
  15.  *    about which system call was invoked and what its arguments consist
  16.  *    of.  The information stored for each argument is described below.
  17.  *
  18.  *    Many system calls, however, are handled exclusively on the
  19.  *    current machine or are processed by special-purpose routines
  20.  *    on the current machine before being sent to the home machine.
  21.  *    In these cases no information about parameter types is kept,
  22.  *    and the procedure is invoked in the same manner as for local
  23.  *    processes.
  24.  *
  25.  *    NOTES ON ADDING SYSTEM CALLS:
  26.  *       Add an entry for the system call to the two arrays
  27.  *       declared below, sysCalls and paramsArray.  For sysCalls,
  28.  *       list the procedures to be invoked, whether to use the
  29.  *       generic stub (in which case special == FALSE), and the number
  30.  *       of words passed to the system call.  For paramsArray, if
  31.  *       special is FALSE, list the type and disposition of each
  32.  *       parameter.  If special is TRUE, just add a comment as a
  33.  *       placeholder within the array.  Finally, add an entry in
  34.  *       procRpc.c for the callback routine corresponding to the new
  35.  *       procedure (NIL if the call is not migrated).
  36.  *
  37.  * Copyright 1985, 1988 Regents of the University of California
  38.  * Permission to use, copy, modify, and distribute this
  39.  * software and its documentation for any purpose and without
  40.  * fee is hereby granted, provided that the above copyright
  41.  * notice appear in all copies.  The University of California
  42.  * makes no representations about the suitability of this
  43.  * software for any purpose.  It is provided "as is" without
  44.  * express or implied warranty.
  45.  */
  46.  
  47. #ifndef lint
  48. static char rcsid[] = "$Header: /sprite/src/kernel/sys/RCS/sysSysCall.c,v 9.8 90/12/06 17:38:21 shirriff Exp $ SPRITE (Berkeley)";
  49. #endif not lint
  50.  
  51. #include <sprite.h>
  52. #include <fs.h>
  53. #include <sys.h>
  54. #include <sysInt.h>
  55. #include <dbg.h>
  56. #include <proc.h>
  57. #include <sync.h>
  58. #include <sched.h>
  59. #include <vm.h>
  60. #include <user/vm.h>
  61. #include <rpc.h>
  62. #include <prof.h>
  63. #include <devVid.h>
  64. #include <net.h>
  65. #include <sysSysCall.h>
  66. #include <sysSysCallParam.h>
  67. #include <status.h>
  68. #include <stdio.h>
  69. #include <sysTestCall.h>
  70.  
  71. /*
  72.  * Forward declarations to procedures defined in this file:
  73.  */
  74.  
  75. static int ErrorProc _ARGS_((void));
  76. static ReturnStatus SysMigCall _ARGS_((Sys_ArgArray args));
  77.  
  78. #define TMP_EXTERN
  79. #ifdef TMP_EXTERN
  80. extern    int Proc_RemoteExec();
  81. #endif
  82.  
  83. #ifndef CLEAN
  84. Boolean sysTraceSysCalls = FALSE;
  85. #endif CLEAN
  86.  
  87. /*
  88.  * For each system call, keep track of:
  89.  *    - which procedure to invoke if the process is local;
  90.  *    - which to invoke if it is remote;
  91.  *    - whether the remoteFunc is "special" and is to be invoked
  92.  *      without interpreting the arguments, or whether the generic
  93.  *      stub will be called (passing it information such as the
  94.  *      number of arguments and the type of system call);
  95.  *    - a pointer to an array of parameter information, which includes
  96.  *      the types and dispositions of each argument.  For "special"
  97.  *      routines, this pointer is NIL.  Refer to sysSysCallParam.h for
  98.  *      documentation on the Sys_CallParam type.
  99.  */
  100.  
  101. typedef struct {
  102.     ReturnStatus (*localFunc)();  /* procedure to invoke for local processes */
  103.     ReturnStatus (*remoteFunc)(); /* procedure to invoke for migrated procs */
  104.     Boolean special;          /* whether the remoteFunc is called without
  105.                      passing it additional information */
  106.     int numWords;          /* The number of 4-byte quantities that must
  107.                      be passed to the system call. */
  108.     Sys_CallParam *paramsPtr;      /* pointer to parameter information for
  109.                      generic stub to use */
  110. } SysCallEntry;
  111.  
  112. /*
  113.  * Sys_ParamSizes is an array of sizes corresponding to
  114.  * each system call argument type.  Sys_ParamSizesDecl is used to
  115.  * assign the elements of the array at compile time.  Due to compiler
  116.  * restrictions, sys_ParamSizes needs to be a "pointer" while
  117.  * sys_ParamSizesDecl is an "array".  The argument types are documented
  118.  * in sysSysCallParam.h.
  119.  */
  120.  
  121. int sys_ParamSizesDecl[] = {
  122.     sizeof(int),            /* SYS_PARAM_INT        */
  123.     sizeof(char),            /* SYS_PARAM_CHAR        */
  124.     sizeof(Proc_PID),            /* SYS_PARAM_PROC_PID        */
  125.     sizeof(Proc_ResUsage),        /* SYS_PARAM_PROC_RES        */
  126.     sizeof(Sync_Lock),            /* SYS_PARAM_SYNC_LOCK        */
  127.     sizeof(Fs_Attributes),        /* SYS_PARAM_FS_ATT        */
  128.     FS_MAX_PATH_NAME_LENGTH,        /* SYS_PARAM_FS_NAME        */
  129.     sizeof(Time),            /* SYS_PARAM_TIMEPTR        */
  130.     sizeof(Time) / 2,            /* SYS_PARAM_TIME1        */
  131.     sizeof(Time) / 2,            /* SYS_PARAM_TIME2        */
  132.     sizeof(int),            /* SYS_PARAM_VM_CMD        */
  133.     0,                     /* SYS_PARAM_DUMMY         */
  134.     sizeof(int),            /* SYS_PARAM_RANGE1         */
  135.     sizeof(int),            /* SYS_PARAM_RANGE2        */
  136.     sizeof(Proc_ControlBlock),        /* SYS_PARAM_PCB        */
  137.     sizeof(Fs_Device),            /* SYS_PARAM_FS_DEVICE        */
  138.     sizeof(Proc_PCBArgString),        /* SYS_PARAM_PCBARG        */
  139.  
  140. };
  141.  
  142. int *sys_ParamSizes = sys_ParamSizesDecl;
  143.  
  144. static int ErrorProc()
  145. {
  146.     printf("Warning: Obsolete system call.\n");
  147.     return(GEN_FAILURE);
  148. }
  149.  
  150. /*
  151.  * sysCalls --
  152.  *
  153.  *    This table is used during a system call trap to branch to the
  154.  *    correct procedure for each system call.  There are two functions,
  155.  *    one if the process is local, the other if the process is an immigrant.
  156.  *    The number of integers (parameters) on the user's stack that have
  157.  *    to be copied to the kernel stack is also listed here.  The last field
  158.  *    of each record is filled in dynamically but initialized here to NIL.
  159.  *
  160.  *    N.B.: The format of this table is relied on to generate the file
  161.  *    Dummy.c, a file with just the declarations of the system calls
  162.  *    and no body.  See the CreateDummy script in src/lib/libc.
  163.  */
  164.  
  165. #define NILPARM ((Sys_CallParam *) NIL)
  166. #define CAST    (ReturnStatus (*) ())
  167.  
  168. static SysCallEntry sysCalls[] = {
  169. /*
  170.  *    localFunc          remoteFunc       special numWords  NILPARM
  171.  */
  172. /* DON'T DELETE THIS LINE - CreateDummy depends on it */
  173.     Proc_Fork,               Proc_Fork,       TRUE,    2,   NILPARM,
  174.     Proc_Exec,               Proc_Exec,       TRUE,    5,   NILPARM,
  175.     CAST Proc_Exit,       CAST Proc_Exit,       TRUE,    1,   NILPARM,
  176.     Sync_WaitTime,           Sync_WaitTime,       TRUE,    2,   NILPARM,
  177.     Test_PrintOut,           Test_PrintOut,      TRUE,       10,   NILPARM,
  178.     Test_GetLine,           Test_GetLine,          TRUE,    2,   NILPARM,
  179.     Test_GetChar,           Test_GetChar,          TRUE,    1,   NILPARM,
  180.     Fs_OpenStub,           Fs_OpenStub,         TRUE,    4,   NILPARM,
  181.     Fs_ReadStub,           Fs_ReadStub,         TRUE,     4,   NILPARM,
  182.     Fs_WriteStub,           Fs_WriteStub,         TRUE,     4,   NILPARM,
  183.     Fs_UserClose,           Fs_UserClose,         TRUE,     1,   NILPARM,
  184.     Fs_RemoveStub,           Fs_RemoveStub,         TRUE,    1,   NILPARM,
  185.     Fs_RemoveDirStub,           Fs_RemoveDirStub,   TRUE,    1,   NILPARM,
  186.     Fs_MakeDirStub,           Fs_MakeDirStub,     TRUE,    2,   NILPARM,
  187.     Fs_ChangeDirStub,           Fs_ChangeDirStub,   TRUE,    1,   NILPARM,
  188.     Proc_Wait,               Proc_Wait,          TRUE,    8,   NILPARM,
  189.     Proc_Detach,           Proc_DoRemoteCall,  FALSE,    1,   NILPARM,
  190.     Proc_GetIDs,           Proc_GetIDs,         TRUE,    4,   NILPARM,
  191.     Proc_SetIDs,           Proc_DoRemoteCall,  FALSE,    2,   NILPARM,
  192.     Proc_GetGroupIDs,           Proc_GetGroupIDs,   TRUE,    3,   NILPARM,
  193. /*
  194.  * Need not be forwarded home because groups only used during FS operations.
  195.  */
  196.     Proc_SetGroupIDs,           Proc_SetGroupIDs,   TRUE,    2,   NILPARM,
  197. /*
  198.  * Must be forwarded home because can ask about arbitrary process on home node.
  199.  */
  200.     Proc_GetFamilyID,           Proc_DoRemoteCall,  FALSE,    2,   NILPARM,
  201.     Proc_SetFamilyID,           Proc_DoRemoteCall,  FALSE,    2,   NILPARM,
  202.     Test_RpcStub,           Test_RpcStub,          TRUE,    4,   NILPARM,
  203.     Sys_StatsStub,           Sys_StatsStub,      TRUE,    4,   NILPARM,
  204.     Vm_CreateVA,           Vm_CreateVA,       TRUE,     2,   NILPARM,
  205.     Vm_DestroyVA,           Vm_DestroyVA,       TRUE,     2,   NILPARM,
  206.     Sig_UserSend,           Sig_UserSend,         TRUE,    3,   NILPARM,
  207.     Sig_Pause,               Sig_Pause,          TRUE,    1,   NILPARM,
  208.     Sig_SetHoldMask,           Sig_SetHoldMask,    TRUE,    2,   NILPARM,
  209.     Sig_SetAction,           Sig_SetAction,      TRUE,    3,   NILPARM,
  210.     Prof_Start,               Prof_Start,         TRUE,    0,   NILPARM,
  211.     Prof_End,               Prof_End,         TRUE,    0,   NILPARM,
  212.     Prof_DumpStub,           Prof_DumpStub,         TRUE,    1,   NILPARM,
  213.     Vm_Cmd,               Vm_Cmd,         TRUE,    2,   NILPARM,
  214.     Sys_GetTimeOfDay,           Proc_DoRemoteCall,  FALSE,    3,   NILPARM,
  215.     Sys_SetTimeOfDay,           Proc_DoRemoteCall,  FALSE,    3,   NILPARM,
  216.     Sys_DoNothing,           Sys_DoNothing,      TRUE,    0,   NILPARM,
  217.     Proc_GetPCBInfo,           Proc_GetPCBInfo,    TRUE,    7,   NILPARM,
  218.     Vm_GetSegInfo,           Vm_GetSegInfo,      TRUE,    4,   NILPARM,
  219.     Proc_GetResUsage,           Proc_GetResUsage,   TRUE,    2,   NILPARM,
  220.     Proc_GetPriority,           Proc_GetPriority,   TRUE,    2,   NILPARM,
  221.     Proc_SetPriority,          Proc_SetPriority,   TRUE,    3,   NILPARM,
  222.     Proc_Debug,               Proc_Debug,          TRUE,    5,   NILPARM,
  223.     Proc_Profile,           Proc_Profile,       TRUE,    6,   NILPARM,
  224.     ErrorProc,               ErrorProc,          TRUE,    2,   NILPARM,
  225.     ErrorProc,                  ErrorProc,        TRUE,    2,   NILPARM,
  226.     Fs_GetNewIDStub,           Fs_GetNewIDStub,    TRUE,    2,   NILPARM,
  227.     Fs_GetAttributesStub,      Fs_GetAttributesStub, TRUE,    3,   NILPARM,
  228.     Fs_GetAttributesIDStub,    Fs_GetAttributesIDStub, TRUE,    2,   NILPARM,
  229.     Fs_SetAttributesStub,      Fs_SetAttributesStub, TRUE,    3,   NILPARM,
  230.     Fs_SetAttributesIDStub,    Fs_SetAttributesIDStub, TRUE,    2,   NILPARM,
  231.     Fs_SetDefPermStub,           Fs_SetDefPermStub,  TRUE,    2,   NILPARM,
  232.     Fs_IOControlStub,           Fs_IOControlStub,   TRUE,    6,   NILPARM,
  233.     Dev_VidEnable,           Proc_DoRemoteCall,  FALSE,    1,   NILPARM,
  234.     /*
  235.      * The following ErrorProc listings correspond to obsolete
  236.      * environment-related procedures.
  237.      */
  238.     ErrorProc,               ErrorProc,  TRUE,    2,   NILPARM,
  239.     ErrorProc,             ErrorProc,  TRUE,    2,   NILPARM,
  240.     ErrorProc,            ErrorProc,  TRUE,    2,   NILPARM,
  241.     ErrorProc,          ErrorProc,   TRUE,    4,   NILPARM,
  242.     ErrorProc,           ErrorProc,   TRUE,    2,   NILPARM,
  243.     ErrorProc,              ErrorProc,  TRUE,    0,   NILPARM,
  244.  
  245.     Sync_SlowLockStub,           Sync_SlowLockStub,  TRUE,    1,   NILPARM,
  246.     Sync_SlowWaitStub,           Sync_SlowWaitStub,  TRUE,    3,   NILPARM,
  247.     Sync_SlowBroadcastStub,    Sync_SlowBroadcastStub,  TRUE,    2,   NILPARM,
  248.     Vm_PageSize,        Vm_PageSize,         TRUE,    1,   NILPARM,
  249.     Fs_HardLinkStub,        Fs_HardLinkStub,   TRUE,    2,   NILPARM,
  250.     Fs_RenameStub,        Fs_RenameStub,        TRUE,    2,   NILPARM,
  251.     Fs_SymLinkStub,        Fs_SymLinkStub,    TRUE,    3,   NILPARM,
  252.     Fs_ReadLinkStub,        Fs_ReadLinkStub,   TRUE,    4,   NILPARM,
  253.     Fs_CreatePipeStub,        Fs_CreatePipeStub, TRUE,    2,   NILPARM,
  254.     VmMach_MapKernelIntoUser,    Proc_RemoteDummy, FALSE,    4,   NILPARM,
  255.     Fs_AttachDiskStub,        Proc_DoRemoteCall, FALSE,    3,   NILPARM,
  256.     Fs_SelectStub,        Fs_SelectStub,        TRUE,    6,   NILPARM,
  257.     CAST Sys_Shutdown,        Sys_Shutdown,        TRUE,    2,   NILPARM,
  258.     Proc_Migrate,        Proc_DoRemoteCall, FALSE,    2,   NILPARM,
  259.     Fs_MakeDeviceStub,        Proc_DoRemoteCall, FALSE,    3,   NILPARM,
  260.     Fs_CommandStub,        Fs_CommandStub,    TRUE,    3,   NILPARM,
  261.     ErrorProc,               ErrorProc,        TRUE,    2,   NILPARM,
  262.     Sys_GetMachineInfo,           Sys_GetMachineInfo,  TRUE,    3,   NILPARM,
  263.     Net_InstallRouteStub,     Net_InstallRouteStub, TRUE,     6,   NILPARM,
  264.     Fs_ReadVectorStub,         Fs_ReadVectorStub, TRUE,     4,   NILPARM,
  265.     Fs_WriteVectorStub,     Fs_WriteVectorStub, TRUE,     4,   NILPARM,
  266.     Fs_CheckAccess,         Fs_CheckAccess,     TRUE,    3,   NILPARM,
  267.     Proc_GetIntervalTimer,    Proc_GetIntervalTimer,     TRUE,    2,   NILPARM,
  268.     Proc_SetIntervalTimer,    Proc_SetIntervalTimer,     TRUE,    3,   NILPARM,
  269.     Fs_FileWriteBackStub,    Fs_FileWriteBackStub, TRUE,    4,   NILPARM,
  270.     Proc_ExecEnv,        Proc_ExecEnv,       TRUE,    4,   NILPARM,
  271.     Fs_SetAttrStub,        Fs_SetAttrStub,       TRUE,    4,   NILPARM,
  272.     Fs_SetAttrIDStub,        Fs_SetAttrIDStub,   TRUE,    3,   NILPARM,
  273.     Proc_GetHostIDs,        Proc_GetHostIDs,   TRUE,    2,   NILPARM,
  274.     Sched_IdleProcessor,    Sched_IdleProcessor,  TRUE,    1,   NILPARM,
  275.     Sched_StartProcessor,    Sched_StartProcessor,   TRUE,    1,   NILPARM,
  276. #if 0
  277.     Mach_GetNumProcessors,    Mach_GetNumProcessors,   TRUE,    1,   NILPARM,
  278. #else
  279.     0,                          0,                      TRUE,   1,   NILPARM,
  280. #endif
  281.     Prof_Profil,                Prof_Profil,            TRUE,   4,   NILPARM,
  282.     Proc_RemoteExec,        Proc_RemoteExec,   TRUE,    4,   NILPARM,
  283.     Sys_GetMachineInfoNew,    Sys_GetMachineInfoNew,   TRUE,    2,   NILPARM,
  284.     Vm_Mmap,            Vm_Mmap,        TRUE,    7,   NILPARM,
  285.     Vm_Munmap,            Vm_Munmap,        TRUE,    3,   NILPARM,
  286.     Vm_Msync,            Vm_Msync,        TRUE,    2,   NILPARM,
  287.     Vm_Mlock,            Vm_Mlock,        TRUE,    2,   NILPARM,
  288.     Vm_Munlock,            Vm_Munlock,        TRUE,    2,   NILPARM,
  289.     Vm_Mincore,            Vm_Mincore,        TRUE,    3,   NILPARM,
  290.     Sync_SemctlStub,        Sync_SemctlStub,    TRUE,    5,   NILPARM,
  291.     Sync_SemgetStub,        Sync_SemgetStub,    TRUE,    4,   NILPARM,
  292.     Sync_SemopStub,        Sync_SemopStub,        TRUE,    4,   NILPARM,
  293.     Vm_Mprotect,        Vm_Mprotect,        TRUE,   3,   NILPARM,
  294. };
  295.  
  296.  
  297. /*
  298.  * paramsArray is a static array of parameter information.  The array is
  299.  * one gigantic array so that it may be initialized at compile time, but
  300.  * conceptually it is distinct arrays, one per system call.  SysInitSysCall,
  301.  * called at system initialization time, maps points within this array
  302.  * to paramsPtr fields within the sysCalls array.  ParamsPtr is initialized
  303.  * to NIL at compile time, but for procedures that are not flagged as
  304.  * "special", paramsPtr is reset to point into paramsArray at the point of
  305.  * the first Sys_CallParam structure corresponding to that procedure.
  306.  *
  307.  * For system calls that are "special", there is no entry in paramsArray.
  308.  * However, a comment with the system call number and " special" is useful
  309.  * to keep track of the correspondence between parameter information and
  310.  * the rest of the sysCall struct.  Note that "special" is equivalent to
  311.  * "local": "special" usually means a special-purpose routine is called,
  312.  * while "local" means the same routine is used for both local and migrated
  313.  * processes.
  314.  *
  315.  * The format of paramsArray is as follows.  For each non-special
  316.  * SysCallEntry, there should be -numWords- Sys_CallParam structures.
  317.  * A number of defined constants are given to simplify the information
  318.  * given for each one.  Essentially, the crucial things to consider are
  319.  * whether a given parameter is passed IN to a procedure, OUT of it, or
  320.  * both.  At the same time, is the parameter passed into the system call
  321.  * in its entirety, such as an integer; or is the parameter a pointer to
  322.  * something that needs to be copied into or out of the kernel address
  323.  * space, or made accessible?  Finally, if the parameter is a pointer, is
  324.  * it a pointer to an object of fixed size or does it point to an array
  325.  * of objects?  The generic stub will handle arrays if the size of the
  326.  * array is an IN parameter that is passed in just before the pointer to
  327.  * the array, in the argument list.  It will also handle arrays with
  328.  * a range of numbers that indicates the size of the array; for example,
  329.  * if the preceding arguments were 2 and 5, the size of the array would
  330.  * be (5 - 2 + 1) * sizeof(...).
  331.  *
  332.  * Note that multi-word parameters must be treated in this array as
  333.  * *separate* arguments.  For example, Time structures are given as
  334.  * TIME1 and TIME2.  This is because the procedures & structures in this
  335.  * file do not know the actual number of arguments, but rather the number
  336.  * of words that a system call is passed.
  337.  */
  338.  
  339. #define PARM         0
  340. #define PARM_I         SYS_PARAM_IN
  341. #define PARM_O         SYS_PARAM_OUT
  342. #define PARM_IO        (SYS_PARAM_IN | SYS_PARAM_OUT)
  343. #define PARM_IA     (SYS_PARAM_IN | SYS_PARAM_ACC)
  344. #define PARM_OA     (SYS_PARAM_OUT | SYS_PARAM_ACC)
  345. #define PARM_IOA    (PARM_IO | SYS_PARAM_ACC)
  346. #define PARM_IC     (SYS_PARAM_IN | SYS_PARAM_COPY)
  347. #define PARM_OC        (SYS_PARAM_OUT | SYS_PARAM_COPY)
  348. #define PARM_IOC    (PARM_IO | SYS_PARAM_COPY)
  349. #define PARM_ICR     (SYS_PARAM_IN | SYS_PARAM_COPY | SYS_PARAM_ARRAY)
  350. #define PARM_OCR    (SYS_PARAM_OUT | SYS_PARAM_COPY | SYS_PARAM_ARRAY)
  351.  
  352. static Sys_CallParam paramsArray[] = {
  353.     /* special */                /* SYS_PROC_FORK    0 */
  354.     /* special */                     /* SYS_PROC_EXEC    1 */
  355.     /* special */                 /* SYS_PROC_EXIT    2 */
  356.     /* local */                          /* SYS_SYNC_WAITTIME    3 */
  357.     /* local */                    /* SYS_TEST_PRINTOUT    4 */
  358.     /* local */                    /* SYS_TEST_GETLINE    5 */
  359.     /* local */                    /* SYS_TEST_GETCHAR    6 */
  360.     /* local */                    /* SYS_FS_OPEN        7 */
  361.     /* local */                    /* SYS_FS_READ        8 */
  362.     /* local */                    /* SYS_FS_WRITE        9 */
  363.     /* local */                    /* SYS_FS_CLOSE        10 */
  364.     /* local */                    /* SYS_FS_REMOVE    11 */
  365.     /* local */                    /* SYS_FS_REMOVE_DIR    12 */
  366.     /* local */                    /* SYS_FS_MAKE_DIR    13 */
  367.     /* local */                    /* SYS_FS_CHANGE_DIR    14 */
  368.     /* special */                     /* SYS_PROC_WAIT    15 */
  369.     SYS_PARAM_INT,          PARM_I,        /* SYS_PROC_DETACH    16 */
  370.     /* local */                         /* SYS_PROC_GETIDS    17 */
  371.     SYS_PARAM_INT,          PARM_I,        /* SYS_PROC_SETIDS    18 */
  372.     SYS_PARAM_INT,          PARM_I,
  373.     /* local */                         /* SYS_PROC_GETGROUPIDS 19 */
  374.     /* local */                         /* SYS_PROC_SETGROUPIDS 20 */
  375.     SYS_PARAM_PROC_PID,          PARM_I,        /* SYS_PROC_GETFAMILYID 21 */
  376.     SYS_PARAM_PROC_PID,          PARM_OC,
  377.     SYS_PARAM_PROC_PID,          PARM_I,        /* SYS_PROC_SETFAMILYID 22 */
  378.     SYS_PARAM_INT,          PARM_I,
  379.     /* test */                    /* SYS_TEST_RPC        23 */
  380.     /* test */                    /* SYS_SYS_STATS    24 */
  381.     /* local */                    /* SYS_VM_CREATEVA    25 */
  382.     /* local */                    /* SYS_VM_DESTROYVA    26 */
  383.     /* local */                    /* SYS_SIG_SEND        27 */
  384.     /* local */                 /* SYS_SIG_PAUSE    28 */
  385.     /* local */                 /* SYS_SIG_SETHOLDMASK    29 */
  386.     /* local */                         /* SYS_SIG_SETACTION    30 */
  387.  
  388.     /* local */                         /* SYS_PROF_START    31 */
  389.     /* local */                         /* SYS_PROF_END        32 */
  390.     /* local */                         /* SYS_PROF_DUMP    33 */
  391.     /* local */                    /* SYS_VM_CMD        34 */
  392.     SYS_PARAM_TIMEPTR,          PARM_OC,        /* SYS_SYS_GETTIMEOFDAY 35 */
  393.     SYS_PARAM_INT,          PARM_OC,
  394.     SYS_PARAM_INT,          PARM_OC,
  395.     SYS_PARAM_TIMEPTR,          PARM_IC,        /* SYS_SYS_SETTIMEOFDAY 36 */
  396.     SYS_PARAM_INT,          PARM_I,
  397.     SYS_PARAM_INT,          PARM_I,
  398.     /* local */                         /* SYS_SYS_DONOTHING    37 */
  399.     /* local */                         /* SYS_PROC_GETPCBINFO    38 */
  400.     /* local */                    /* SYS_VM_GETSEGINFO    39 */
  401.     /* local */                    /* SYS_PROC_GETRESUSAGE 40 */
  402.     /* local */                    /* SYS_PROC_GETPRIORITY 41 */
  403.     /* local */                    /* SYS_PROC_SETPRIORITY 42 */
  404.     /* special (don't migrate?) */             /* SYS_PROC_DEBUG    43 */
  405.     /* local case not implemented */        /* SYS_PROC_PROFILE    44 */
  406.     /* local */                    /* SYS_FS_TRUNC        45 */
  407.     /* local */                    /* SYS_FS_TRUNC_ID    46 */
  408.     /* local */                 /* SYS_FS_GET_NEW_ID    47 */
  409.     /* local */                    /* SYS_FS_GET_ATTRIBUTES 48 */
  410.     /* local */                 /* SYS_FS_GET_ATTR_ID    49 */
  411.     /* local */                    /* SYS_FS_SET_ATTRIBUTES 50 */
  412.     /* local */                 /* SYS_FS_SET_ATTR_ID    51 */
  413.     /* local */                    /* SYS_FS_SET_DEF_PERM    52 */
  414.     /* local */                         /* SYS_FS_IO_CONTROL    53 */
  415.     SYS_PARAM_INT,          PARM_I,        /* SYS_SYS_ENABLEDISPLAY 54 */
  416.     /* obsolete */                /* SYS_PROC_SET_ENVIRON 55 */
  417.     /* obsolete */                /* SYS_PROC_UNSET_ENVIRON 56 */
  418.     /* obsolete */                /* ..._GET_ENVIRON_VAR    57 */
  419.     /* obsolete */                /* ..._GET_ENVIRON_RANGE 58 */
  420.     /* obsolete */                /* ..._INSTALL_ENVIRON    59 */
  421.     /* obsolete */                /* SYS_PROC_COPY_ENVIRON 60 */
  422.     /* local */                    /* SYS_SYNC_SLOWLOCK    61 */
  423.     /* local */                    /* SYS_SYNC_SLOWWAIT    62 */
  424.     /* local */                    /* SYS_SYNC_SLOWBROADCAST 63 */
  425.     /* local */                    /* SYS_VM_PAGESIZE    64 */
  426.     /* local */                    /* SYS_FS_HARDLINK    65 */
  427.     /* local */                    /* SYS_FS_RENAME    66 */
  428.     /* local */                    /* SYS_FS_SYMLINK    67 */
  429.     /* local */                    /* SYS_FS_READLINK    68 */
  430.     /* local */                    /* SYS_FS_CREATEPIPE    69 */
  431.     SYS_PARAM_INT,          PARM_I,        /* ..VM_MAPKERNELINTOUSER 70 */
  432.     SYS_PARAM_INT,          PARM_I,
  433.     SYS_PARAM_INT,          PARM_I,
  434.     SYS_PARAM_INT,          PARM_OC,
  435.     SYS_PARAM_FS_NAME,          PARM_IA,        /* SYS_FS_ATTACH_DISK    71 */
  436.     SYS_PARAM_FS_NAME,          PARM_IA,
  437.     SYS_PARAM_INT,          PARM_I,
  438.     /* local */                         /* SYS_FS_SELECT    72 */
  439.     /* local */                    /* SYS_SYS_SHUTDOWN    73 */
  440.     SYS_PARAM_PROC_PID,          PARM_I,        /* SYS_PROC_MIGRATE    74 */
  441.     SYS_PARAM_INT,          PARM_I,
  442.     SYS_PARAM_FS_NAME,           PARM_IA,        /* SYS_FS_MAKE_DEVICE    75 */
  443.     SYS_PARAM_FS_DEVICE,      PARM_IC,
  444.     SYS_PARAM_INT,          PARM_I,
  445.     /* local */                    /* SYS_FS_COMMAND    76 */
  446.     /* local */                    /* -obsolete-        77 */
  447.     /* local */                    /* SYS_GETMACHINEINFO    78 */
  448.     /* special */                /* SYS_NET_INSTALL_ROUTE 79 */
  449.     /* local */                    /* SYS_FS_READVECTOR    80 */
  450.     /* local */                    /* SYS_FS_WRITEVECTOR    81 */
  451.     /* local */                    /* SYS_FS_CHECKACCESS    82 */
  452.     /* local */                /* SYS_PROC_GETINTERVALTIMER    83 */
  453.     /* local */                /* SYS_PROC_SETINTERVALTIMER    84 */
  454.     /* local */                /* SYS_FS_WRITEBACKID        85 */
  455.     /* special */                     /* SYS_PROC_EXEC_ENV    86 */
  456.     /* local */                /* SYS_FS_SET_ATTR_NEW        87 */
  457.     /* local */             /* SYS_FS_SET_ATTR_ID_NEW    88 */
  458.     /* local */             /* SYS_PROC_GETHOSTIDS        89 */
  459.     /* local */             /* SYS_SCHED_IDLE_PROCESSOR    90 */
  460.     /* local */             /* SYS_SCHED_START_PROCESSOR    91 */
  461.     /* local */             /* SYS_MACH_NUM_PROCESSORS    92 */
  462.     /* local */                         /* SYS_PROF_PROFIL              93 */
  463.     /* local */                         /* SYS_PROC_REMOTE_EXEC         94 */
  464.     /* local */                         /* SYS_SYS_GETMACHINEINFO_NEW   95 */
  465.     /* local */                         /* SYS_VM_MMAP            96 */
  466.     /* local */                         /* SYS_VM_MUNMAP        97 */
  467.     /* local */                         /* SYS_VM_MSYNC            98 */
  468.     /* local */                         /* SYS_VM_MLOCK            99 */
  469.     /* local */                         /* SYS_VM_MUNLOCK        100 */
  470.     /* local */                         /* SYS_VM_MINCORE        101 */
  471.     /* local */                         /* SYS_SYNC_SEMCTL        102 */
  472.     /* local */                         /* SYS_SYNC_SEMGET        103 */
  473.     /* local */                         /* SYS_SYNC_SEMOP        104 */
  474.     /* local */                         /* VM_MPROTECT            105 */
  475.     /*
  476.      * Insert new system call information above this line.
  477.      */
  478.     NIL,              NIL        /* array compatibility check */
  479. };
  480.  
  481. /*
  482.  * Define an array to count the number of system calls performed for local
  483.  * and foreign processes, as well as subscripts and a macro to reset it.
  484.  */
  485.  
  486. #define LOCAL_CALL 0
  487. #define FOREIGN_CALL 1
  488. int sys_NumCalls[SYS_NUM_SYSCALLS];
  489. #define RESET_NUMCALLS() bzero((Address) sys_NumCalls, \
  490.                 SYS_NUM_SYSCALLS * sizeof(int));
  491.  
  492.  
  493. /*
  494.  *----------------------------------------------------------------------
  495.  *
  496.  * SysInitSysCall --
  497.  *
  498.  *    Initialize the data structures for performing a system call.
  499.  *    Make sure the last entry in the array of parameters is (NIL, NIL)
  500.  *     (serving as a cross check on the total number of parameters to
  501.  *    be initialized).  Initialize the count of the number of system
  502.  *    calls performed.
  503.  *
  504.  * Results:
  505.  *    None.
  506.  *
  507.  * Side effects:
  508.  *    The mapping between system calls and their argument types is
  509.  *    established.
  510.  *
  511.  *----------------------------------------------------------------------
  512.  */
  513.  
  514. void
  515. SysInitSysCall()
  516. {
  517.     int sysCallNum;
  518.     SysCallEntry *entryPtr;
  519.     Sys_CallParam *paramPtr;
  520.  
  521.     paramPtr = paramsArray;
  522.     entryPtr = sysCalls;
  523.     for (sysCallNum = 0; sysCallNum < SYS_NUM_SYSCALLS; sysCallNum++) {
  524.     if (!entryPtr->special) {
  525.         entryPtr->paramsPtr = paramPtr;
  526.         paramPtr += entryPtr->numWords;
  527.     /*
  528.      * Won't lint due to cast of function pointer.
  529.      */
  530. #ifndef lint
  531.         Mach_InitSyscall(sysCallNum, entryPtr->numWords,
  532.             entryPtr->localFunc, SysMigCall);
  533. #endif /* lint */
  534.     } else {
  535.     /*
  536.      * Won't lint due to cast of function pointer.
  537.      */
  538. #ifndef lint
  539.         Mach_InitSyscall(sysCallNum, entryPtr->numWords,
  540.             entryPtr->localFunc, entryPtr->remoteFunc);
  541. #endif /* lint */
  542.     }
  543.     entryPtr++;
  544.     }
  545.     if (paramPtr->type != NIL || paramPtr->disposition != NIL) {
  546.     panic("SysInitSysCall: error initializing parameter array.\n");
  547.     }
  548.     RESET_NUMCALLS();
  549. }
  550.  
  551. /*
  552.  *----------------------------------------------------------------------
  553.  *
  554.  * SysMigCall --
  555.  *
  556.  *    This procedure is invoked whenever a migrated process invokes
  557.  *    a kernel call that doesn't have "special" set.  It arranges
  558.  *    for the kernel call to be sent home in a standard fashion.
  559.  *
  560.  * Results:
  561.  *    Returns the result of the kernel call, whatever that is.
  562.  *
  563.  * Side effects:
  564.  *    Depends on the kernel call.
  565.  *
  566.  *----------------------------------------------------------------------
  567.  */
  568.  
  569. static ReturnStatus
  570. SysMigCall(args)
  571.     Sys_ArgArray args;            /* The arguments to the system call. */
  572. {
  573.     int sysCall;
  574.     register SysCallEntry *entryPtr;
  575.  
  576.     sysCall = Mach_GetLastSyscall();
  577.     entryPtr = &sysCalls[sysCall];
  578.     return (*entryPtr->remoteFunc)(sysCall, entryPtr->numWords,
  579.         (ClientData *) &args, entryPtr->paramsPtr);
  580. }
  581.  
  582. /*
  583.  *----------------------------------------------------------------------
  584.  *
  585.  * Sys_OutputNumCalls --
  586.  *
  587.  *    Copy the number of invocations of system calls into user space.
  588.  *    Takes an argument, the number of calls to copy, which indicates the
  589.  *    size of the user's buffer.  This is protection against any
  590.  *    inconsistency between the kernel and user program's ideas of how
  591.  *    many system calls there are.  An argument of 0 calls indicates that
  592.  *    the statistics should be reset to 0.
  593.  *
  594.  * Results:
  595.  *    The return status from Vm_CopyOut is returned.
  596.  *
  597.  * Side effects:
  598.  *    Data is copied into user space.
  599.  *
  600.  *----------------------------------------------------------------------
  601.  */
  602.  
  603. ReturnStatus
  604. Sys_OutputNumCalls(numToCopy, buffer)
  605.     int numToCopy;    /* number of system calls statistics to copy */
  606.     Address buffer;
  607. {
  608.     ReturnStatus status = SUCCESS;
  609.  
  610.     if (numToCopy == 0) {
  611.     RESET_NUMCALLS();
  612.     } else {
  613.     /*
  614.      * Are arrays stored in row-major or column-major order???
  615.      */
  616.     status = Vm_CopyOut(numToCopy * sizeof(int), (Address) sys_NumCalls,
  617.                 buffer);
  618.     }
  619.     return(status);
  620. }
  621.